# -*- coding:utf-8 -*-
from pymongo import MongoClient

conn = MongoClient("127.0.0.1", 27017);
db = conn.stk;  # 如果不存在，则自动创建
tmp_set = db.tmp_set;  # 如果不存在，则自动创建

# 新增
tmp_set.insert({"name": "zhangsan", "age": 18});
tmp_set.save({"name": "zhangsan2", "age": 182});

users = [{"ts_code":"000001.SZ","symbol":"000001","name":"\u5e73\u5b89\u94f6\u884c","area":"\u6df1\u5733","industry":"\u94f6\u884c","market":"\u4e3b\u677f","list_date":"19910403"}]
tmp_set.insert(users)

# 查询
for i in tmp_set.find():
  print("find all:" , i);

for i in tmp_set.find({"name": "zhangsan"}):
  print("find with condition:", i);

print("find one:" , tmp_set.find_one({"name": "zhangsan"}))

# 修改
tmp_set.update({"name":"zhangsan"},{'$set':{"age":20}})

# 删除
tmp_set.remove({'name': 'zhangsan'})


